<!DOCTYPE html>
<html lang="en">
<title>教练历史课时费列表</title>
<#import "/layout/layout.html" as body/>
<@body.page>
<div class="wrapper wrapper-content animated fadeIn">
    <div class="tabs-container">
        <ul class="nav nav-tabs">
            <li class="active"><a onclick='loadFeeList(0)' data-toggle="tab" href="#tab-1" aria-expanded="true">团体课程</a></li>
            <li class=""><a onclick='loadPrivateFeeList(0)' data-toggle="tab" href="#tab-2" aria-expanded="false">私教课程</a></li>
            <li class=""><a  onclick='loadCampFeeList(0)' data-toggle="tab" href="#tab-3" aria-expanded="false">檬营课程</a></li>
        </ul>
        <div class="tab-content">
        <input type="hidden" id="coachId" name="coachId" value="${coachId}">
        <input type='hidden' id='yearMonth' name='yearMonth' value="${yearMonth}"/>

            <!--团体课程-->
            <div id="tab-1" class="tab-pane active">
                <div class="panel-body">
                    <div class="wrapper wrapper-content animated fadeInRight" style="padding-top: 0">
                        <div class="row">
                            <div class="col-lg-12">
                                <div class="ibox float-e-margins">
                                    <div class="ibox-content" style="border-color: #fff">
                                        <div class="table-responsive">
                                            <form id='searchForm' class="form-inline" role="form">
                                                <div class="form-group">
                                                    <label for="classId">课程ID：</label>
                                                    <input class="form-control" type="text" id="courseId" name="courseId" placeholder="输入课程Id"/>
                                                </div>
                                                <div class="form-group margin-left">
					                                <label>门店：</label>
					                                <select class="form-control" id="storeId" name="storeId">
					                                    <option value="0">全部</option>
					                                    <#if stores??>
					                                        <#list stores as store>
					                                            <option value="${store.id}">${store.storeName}</option>
					                                        </#list>
					                                    </#if>
					                                </select>
					                            </div>
					                            
                                                <button type="button" id="bottomSearch" class="btn btn-outline btn-primary" style="margin-top: 5px">确认</button>
                                            	<button type="button" id="downLoadTeam" class="btn btn-outline excelButton" style="margin-top: 5px">导出明细</button>
                                            </form>
                                            <table class="table table-hover table-center dataTables-example">
                                                <thead>
                                                <tr>
                                                    <th>上课时间</th>
                                                    <th>课程名称</th>
                                                    <th>课程ID</th>
                                                    <th>原价|会员价</th>
                                                    <th>门店</th>
                                                    <th>上限</th>
                                                    <th>已报</th>
                                                    <th>排队</th>
                                                    <th>团课包月</th>
                                                    <th>白板</th>
                                                    <th>课时费</th>
                                                    <th>爆场</th>
                                                    <th>小计</th>
                                                </tr>
                                                </thead>
                                                <tbody id='teamFeeList'>
                                                
                                                </tbody>
                                            </table>
                                        </div>
                                    </div>
                                    <div class="ibox-footer overflow">
                                        <h4 class="pull-left" id='total_count'>合计：¥76000</h4>
                                        <div class="pull-right copot-page" id='teamFeeListPage'></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!--私教课程-->
            <div id="tab-2" class="tab-pane">
                <div class="panel-body">
                    <div class="wrapper wrapper-content animated fadeInRight" style="padding-top: 0">
                        <div class="row">
                            <div class="col-lg-12">
                                <div class="ibox float-e-margins">
                                    <div class="ibox-content" style="border-color: #fff">
                                        <div class="table-responsive">
                                            <form class="form-inline" role="form">
                                                <div class="form-group">
                                                    <label for="orderId">订单ID：</label>
                                                    <input class="form-control" type="text" id="orderId" name="orderId" placeholder="输入订单ID"/>
                                                </div>
                                                <select class="form-control" id="storeIdP" name="storeId">
					                                    <option value="0">全部</option>
					                                    <#if stores??>
					                                        <#list stores as store>
					                                            <option value="${store.id}">${store.storeName}</option>
					                                        </#list>
					                                    </#if>
					                            </select>
                                                <button type="button" id="privateSearch" class="btn btn-outline btn-primary" style="margin-top: 5px">确认</button>
                                                <button type="button" id="downLoadPri" class="btn btn-outline excelButton" style="margin-top: 5px">导出明细</button>
                                            </form>
                                            <table class="table table-hover table-center dataTables-example">
                                                <thead>
                                                <tr>
                                                    <th>销课时间</th>
                                                    <th>课程名称</th>
                                                    <th>订单ID</th>
                                                    <th>销课门店</th>
                                                    <th>课时</th>
                                                    <th>用户</th>
                                                    <th>订单总额</th>
                                                    <th>课时单价</th>
                                                    <th>分成比例</th>
                                                    <th>课时费</th>
                                                </tr>
                                                </thead>
                                                <tbody id='privateFeeList'>
                                                
                                                </tbody>
                                            </table>
                                        </div>
                                    </div>
                                    <div class="ibox-footer overflow">
                                        <h4 id='private_total_count' class="pull-left">合计：¥76000</h4>
                                        <div class="pull-right copot-page" id='privateFeeListPage'></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!--檬营课程-->
            <div id="tab-3" class="tab-pane">
                <div class="panel-body">
                    <div class="wrapper wrapper-content animated fadeInRight" style="padding-top: 0">
                        <div class="row">
                            <div class="col-lg-12">
                                <div class="ibox float-e-margins">
                                    <div class="ibox-content" style="border-color: #fff">
                                        <div class="table-responsive">
                                            <form class="form-inline" role="form">
                                                <div class="form-group">
                                                    <label for="classId">课程ID：</label>
                                                    <input class="form-control" type="text" id="campCourseId" name="campCourseId" placeholder="课程ID"/>
                                                </div>
                                                <select class="form-control" id="storeIdC" name="storeIdC">
					                                    <option value="0">全部</option>
					                                    <#if stores??>
					                                        <#list stores as store>
					                                            <option value="${store.id}">${store.storeName}</option>
					                                        </#list>
					                                    </#if>
					                            </select>
                                                <button type="button" id="campSearch" class="btn btn-outline btn-primary" style="margin-top: 5px">确认</button>
                                                <button type="button" id="downLoadCamp" class="btn btn-outline excelButton" style="margin-top: 5px">导出明细</button>
                                            </form>
                                            <table class="table table-hover table-center dataTables-example">
                                                <thead>
                                                <tr>
                                                    <th>开始时间</th>
                                                    <th>结束时间</th>
                                                    <th>课程名称</th>
                                                    <th>课程ID</th>
                                                    <th>原价|会员价</th>
                                                    <th>课程总实收</th>
                                                    <th>门店</th>
                                                    <th>课时</th>
                                                    <th>上限</th>
                                                    <th>已报</th>
                                                    <th>排队</th>
                                                    <th>方案A</th>
                                                    <th>方案B</th>
                                                </tr>
                                                </thead>
                                                <tbody id='campFeeList'>
                                                
                                                </tbody>
                                            </table>
                                        </div>
                                    </div>
                                    <div class="ibox-footer overflow">
                                        <h4 id='camp_total_count' class="pull-left">合计：¥76000</h4>
                                        <div class="pull-right copot-page" id='campFeeListPage'></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
	
    $(document).ready(function () {
		
    	loadFeeList(0);

        function getarg(url) {
            var arg = url.split("#");
            return arg[1];
        }

        var _url = getarg(window.location.href);
        $('.nav-tabs a[href="#' + _url + '"]').tab('show');

        console.log(getarg(window.location.href));

        <!-- Enable portlets -->
//        WinMove();
        $(".is-drag").sortable({
            cursor: "move",
            items: ".is-drag-li",               //只是li可以拖动
            opacity: 0.6,                       //拖动时，透明度为0.6
            revert: true,                       //释放时，增加动画
            update: function (event, ui) {       //更新排序之后
                console.log($(this).sortable("toArray"));
                //console.log($(this).sortable('serialize',{ key:'id', expression: /(.*)/}))
            }
        });
        //
        $('.btn-delete').click(function () {
            swal({
                title: "确定删除吗?",
                text: "删除后不可恢复!",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                cancelButtonText: "容我三思！",
                confirmButtonText: "删除!",
                closeOnConfirm: false
            }, function () {
                swal("Deleted!", "Your imaginary file has been deleted.", "success");
            });
        });
        
        $("#bottomSearch").click(function(){
        	loadFeeList(0)
        })
        $("#campSearch").click(function(){
        	loadCampFeeList(0)
        })
        $("#privateSearch").click(function(){
        	loadPrivateFeeList(0)
        })
        
        $("#downLoadTeam").click(function(){
        	downloadFeeDetail(1)
        })
        $("#downLoadPri").click(function(){
        	downloadFeeDetail(2)
        })
        $("#downLoadCamp").click(function(){
        	downloadFeeDetail(3)
        })
        
    });
    
    function downloadFeeDetail(type) {
    	var yearMonth = $("#yearMonth").val();
    	var storeId = $('#storeId option:selected').val();
        var coachId = $("#coachId").val();
        var courseId = $("#courseId").val();
    	 debugger
        $.post("${baseUrl}system/coach/download_fee_detail?type=" + type + "&yearMonth=" +yearMonth+ "&storeId="+storeId+"&courseId="+courseId+"&coachId="+coachId, function (res) {
            res = eval("(" + res + ")");
            if (res && res.data.result == "success") {
                swal("成功!", '文件下载成功！', "success");
                window.location = "${baseUrl}system/cashcard/download_file?fileName=" + res.data.fileName;
            } else {
                swal("错误!", res.data.msg, "error");
            }
        });
    }
    
    //团课
	function loadFeeList(currentIndex) {
		var param = {
            "pageIndex": currentIndex,
            "pageSize": 100,
            "storeId": $('#storeId option:selected').val(),
            "coachId": $("#coachId").val(),
            "courseId":$("#courseId").val(),
            "yearMonth":$("#yearMonth").val(),
        };
		$.post(
          "${baseUrl}system/coach/fee_list",
          param,
          function(result){
        	  var totale = 0
        	  console.log(result)
        	  var html = "";
              var workType = null;
              var storeName = null;
              var status = 0;
              var countBlank = 0;
              var countHot = 0;
              $.each(result.feeList, function (i, data) {
                 if(data.hotCourse > 0) countHot++;
                 if(data.blankCourse > 0) countBlank++;
            	  totale += (data.hotCourse + data.nomalCourse + data.blankCourse);
                  html += "<tr><td>" + data.startTime + "</td>";
                  html += "<td>" + data.serviceName + "</td>";
                  html += "<td>" + data.courseId + "</td>";
                  html += "<td>" + data.price +"|"+ data.primePrice + "</td>";
                  html += "<td>" + data.storeName + "</td>";
                  html += "<td>" + data.maxCount + "</td>";
                  html += "<td>" + data.currentCount + "</td>";
                  html += "<td>" + data.waitCount + "</td>";
                  html += "<td>" + data.monthTeamCardOrderCn + "</td>";
                  html += "<td>" + data.blankCourse + "</td>";
                  html += "<td>" + data.nomalCourse + "</td>";
                  html += "<td>" + data.hotCourse + "</td>";
                  html += "<td>" + (data.hotCourse + data.nomalCourse + data.blankCourse) + "</td>";
                  //html += "<td width='160'>";
                 
                  html += "</td>";
                  html += "</tr>";
              });
              
              $("#total_count").html("合计：" + totale + ",&nbsp;&nbsp;白板课：" + countBlank + ",&nbsp;&nbsp;爆场课："+countHot+ ",&nbsp;&nbsp;正常课：" + (result.feeListCount - (countBlank + countHot )));
              $("#teamFeeList").html(html);
          }
	 	)
	}
    
    //私教
    
	function loadPrivateFeeList(currentIndex = 0) {
		var param = {
            "pageIndex": currentIndex,
            "pageSize": 100,
            "storeId": $('#storeIdP option:selected').val(),
            "coachId": $("#coachId").val(),
            "orderId":$("#orderId").val(),
            "yearMonth":$("#yearMonth").val(),
        };
		$.post(
          "${baseUrl}system/coach/private_fee_list",
          param,
          function(result){
        	  var priTotale = 0
        	  console.log(result)
        	  var html = "";
              
              if(result.priFeeList.length == 0){
            	  html += "<tr><td colspan=\"7\">没有数据！</td></tr>";
              }
              $.each(result.priFeeList, function (i, data) {
					
                  priTotale += data.real_amt;
                  html += "<tr><td>" + data.closeTime + "</td>";
                  html += "<td>" + data.serviceName + "</td>";
                  html += "<td>" + data.orderId + "</td>";
                  html += "<td>" + data.storeName + "</td>";
                  html += "<td>" + data.courseNumber +"|"+ data.courseCount + "</td>";
                  html += "<td>" + data.nickName+"/"+ data.mobile + "</td>";
                  html += "<td>" + data.amount + "</td>";
                  html += "<td>" +data.per_course_amt+ "</td>";
                  html += "<td>" +data.priCourseRate+ "</td>";
                  html += "<td>" + data.real_amt + "</td>";
                 
                  //html += "<td width='160'>";
                 
                  html += "</td>";
                  html += "</tr>";
              });
              
              $("#private_total_count").html("合计：" + priTotale);
              $("#privateFeeList").html(html);
          }
	 	)
	}
    
    //训练营
    
	function loadCampFeeList(currentIndex) {
		var param = {
            "pageIndex": currentIndex,
            "pageSize": 100,
            "storeId": $('#storeIdC option:selected').val(),
            "coachId": $("#coachId").val(),
            "courseId":$("#campCourseId").val(),
            "yearMonth":$("#yearMonth").val(),
        };
		$.post(
          "${baseUrl}system/coach/camp_fee_list",
          param,
          function(result){
        	  var campTotale = 0
        	  console.log(result)
        	  var html = "";
              
              $.each(result.campFeeList, function (i, data) {
            	
            	  
                  campTotale += ((data.palnB > data.planA) ? data.palnB : data.planA);
                  html += "<tr><td>" + data.courseSigninStartTime + "</td>";
                  html += "<td>" + data.courseSigninEndTime + "</td>";
                  html += "<td>" + data.serviceName + "</td>";
                  html += "<td>" + data.courseId + "</td>";
                  html += "<td>" + data.price +"|"+ data.primePrice + "</td>";
                  html += "<td>" + data.course_order_amt + "</td>";
                  html += "<td>" + data.storeName + "</td>";
                  html += "<td>" + data.courseNumber + "</td>";
                  html += "<td>" + data.maxCount + "</td>";
                  html += "<td>" + data.currentCount + "</td>";
                  html += "<td>" + data.waitCount + "</td>";
                  html += "<td>" + data.planA + "</td>";
                  html += "<td>" + data.palnB + "</td>";
                  //html += "<td width='160'>";
                  
                  html += "</td>";
                  html += "</tr>";
              });
              
              $("#camp_total_count").html("合计：" + campTotale);
              $("#campFeeList").html(html);
          }
	 	)
	}
</script>
</@body.page>
</html>